# __author: Rachel章
# data: 2023/4/23
# desc: 会员API
import requests

from common.config import getconf


class Member:
    # 会员列表查询-全部
    def query_member_list_01(self, env, qwc_token, current=1, size=20):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-member-server/v1/member/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "regBusinessTypes": [],
            "regEventTypes": [],
            "registerChannelTypes": [],
            "current": current,
            "size": size
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 会员列表查询-所有查询条件
    def query_member_list_02(self, env, qwc_token, identifierNs, keyWord, memberIdentifierType, regBusinessTypes,
                             regEventTypes,
                             registerChannelTypes, registerDataBegin, registerDataEnd, current=1, size=20):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-member-server/v1/member/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "identifierNs": identifierNs,
            "keyWord": keyWord,
            "memberIdentifierType": memberIdentifierType,
            "regBusinessTypes": regBusinessTypes,
            "regEventTypes": regEventTypes,
            "registerChannelTypes": registerChannelTypes,
            "registerDataBegin": registerDataBegin,
            "registerDataEnd": registerDataEnd,
            "current": current,
            "size": size
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 会员列表查询-关键词
    def query_member_list_03(self, env, qwc_token, keyWord, current=1, size=20):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-member-server/v1/member/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "regBusinessTypes": [],
            "regEventTypes": [],
            "registerChannelTypes": [],
            "keyWord": keyWord,
            "current": current,
            "size": size
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 会员详情
    def query_member_detail_01(self, env, qwc_token, id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-member-server/v1/member/info/" + id
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        return requests.get(url, headers=headers).json()

    # 会员详情-绑定平台
    def query_member_detail_02(self, env, qwc_token, id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-member-server/v1/member/queryPlatformList/" + id
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "memberId": id,
            "bindStatus": 1
        }
        return requests.post(url, headers=headers, json=dict).json()
